package com.rxjava.myrxjava;

import com.rxjava.myrxjava.os.Handler;

/**
 * Created by iceGeneral on 2016/10/15.
 */
public class Test2 {
    public static void main(String[] args) {
    	Handler handler = new Handler();
        
    	Observable<Integer> o1 = Observable.create(new OnSubscribe<Integer>() {
            @Override
            public void call(Subscriber<? super Integer> subscriber) {
            	System.out.println("o1: " + Thread.currentThread().getName());
            	try {
					Thread.sleep(500);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
            	subscriber.onNext(8);
            }
        });
        
        Observable<String> o2 = Observable.create(new OnSubscribe<String>() {
            @Override
            public void call(Subscriber<? super String> subscriber) {
            	System.out.println("o2: " + Thread.currentThread().getName());
            	try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
                subscriber.onNext("A");
            }
        });
        
        Observable.zip(o1, o2, new Func2<Integer, String, String>() {
            @Override
            public String call(Integer integer, String s) {
            	System.out.println("zip: " + Thread.currentThread().getName());
            	return "zip" + integer + s;
            }
        })
        .subscribeOnIO()
        .observeOn(handler)
        .subscribe(new Subscriber<String>() {
            @Override
            public void onNext(String s) {
            	System.out.println("sub: " + Thread.currentThread().getName());
                System.out.println(s);
            }
        });
        System.out.println("main go no: " + Thread.currentThread().getName());
        handler.loop();
    }

}
